package com.twu.biblioteca;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//Eventually maybe I should extract out fields and methods pertaining to books into a "Library" class.

public class BibliotecaApp {

    public List<String> bookList = new ArrayList<String>(
            Arrays.asList("Book One", "Book Two", "Book Three"));
    private PrintStream stream;

    public BibliotecaApp(PrintStream stream) {
        this.stream = stream;
    }

    public void go() {
        InputStreamReader inputData = new InputStreamReader(System.in);
        BufferedReader bufferdReader = new BufferedReader(inputData);

        stream.println("Welcome!!");

        mainMenu(bufferdReader);

    }

    public void mainMenu(BufferedReader bufferedReader) {
        stream.println("Main Menu:");
        stream.println("List Books");
        try {
            String userInput = bufferedReader.readLine();
            if (userInput.equalsIgnoreCase("List Books")) {
                listBooks();

            } else {
                System.out.println("Select a valid option!");
            }
        } catch (IOException exception) {
            System.out.println(exception);
        }
    }

    private String formatBookList(List<String> bookList) {
        String listAsString = bookList.toString();

        return listAsString.substring(1, listAsString.length() - 1);
    }

    public void listBooks() {
        String bookListString = formatBookList(bookList);
        stream.println(bookListString);

    }


}
